Skip to content

Conversation

@baileympearson
Copy link
Contributor

Description

Summary of Changes

Notes for Reviewers

What is the motivation for this change?

Release Highlight

Release notes highlight

Double check the following

  • Lint is passing (npm run check:lint)
  • Self-review completed using the steps outlined here
  • PR title follows the correct format: type(NODE-xxxx)[!]: description
    • Example: feat(NODE-1234)!: rewriting everything in coffeescript
  • Changes are covered by tests
  • New TODOs have a related JIRA ticket

{},
{ serverSelectionTimeoutMS: 10 }
);
const topology = topologyWithPlaceholderClient('someserver:27019', {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NB: this change is not necessary (along with the change in tools/utils.ts) but without this change, we don't actually use serverSelectionTimeoutMS: 10 in the test, and the test takes 30s instead of 10ms.

The test works just fine either way.

) => ServerDescription[];

/** @internal */
export class DeprioritizedServers {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could also have either been a type alias to Set<string> or a subclass of Set<string> but I liked the dedicated class approach because:

  • it is explicit and clear
  • it doesn't expose extra APIs (i.e., no extra unneeded set methods)
  • it is more convenient to interact with it externally using only ServerDescriptions, and it becomes an implementation detail that it only contains strings.

const primary: ServerDescription = Array.from(topologyDescription.servers.values()).filter(
primaryFilter
)[0];

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a chunk of "clean ups" that I put in this PR. I've separated them into a single commit to make reviewing easier, but basically they boil down to just replacing Array.reduce calls that perform as filters with filter. You can view those changes by just reviewing the first commit of this PR.

}

return true;
return Object.entries(tagSet).every(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

misc cleanup. can revert.

!deprioritized.has(server);
}

function secondarySelector(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rest of the changes in this file are pretty in depth, but they helped me when I was writing this code and I think they'll help reviewers and devs going forward.

I migrated to switch statements for clarity and exhaustiveness checking.

topologyDescription: TopologyDescription,
servers: ServerDescription[],
deprioritized?: ServerDescription[]
deprioritized: DeprioritizedServers
Copy link
Contributor Author

@baileympearson baileympearson Dec 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Making deprioritized servers is an opinionated choice that resulted in a ton of small test changes. I prefer this approach because forcing callers to provide this prevents scenarios where callers forget to provide DeprioritizedServers when they should.

Happy to reconsider though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants